from app.db.mongoClient import ErrMongoClient, get_mongo_client
from . import dbSynPosServer, collectionServerList


def editSchoolNameLogo(schoolName, schoolLogo):
    '''
    设置学校名称及logo
    '''
    try:
        mg_client = get_mongo_client()
        collection = mg_client[dbSynPosServer][collectionServerList]
        res = collection.find_one()
        # 数据库里存在
        if res is not None:
            return collection.update(
                {'schoolName': res.get('schoolName')},
                {'$set': {
                    'schoolName': schoolName,
                    'schoolLogo': schoolLogo
                }})

        data = {'schoolName': schoolName, 'schoolLogo': schoolLogo}
        return collection.insert_one(data)

    except Exception as e:
        raise ErrMongoClient.data(str(e))
